{% extends "admin/change_form.html" %}
{% load i18n admin_modify adminmedia %}

{% block stylesheets %}
  {{ block.super }}
   <style type="text/css">
      .level {
         background-color:#eeeeee;
         font-size:120%;
         border:1px solid;
         padding: 2px;
         margin: 2px;
         line-height: 23px;
      }
      
      .level_complete {
         background-color:rgb(0,255,0);
      }
      textarea {
         height: 30px !important;
         width: 500px !important;
      }
      .original {
         font-size:0px;
      }
      .inline-group .tabular tr.has_original td {
         padding-top: 1em !important;
      }
      .form-container .module {
         min-width: 300px;
      }

      .row .vTextField, 
      .row .vURLField, 
      .row .vFileBrowseField, 
      .row textarea, 
      .row .vLargeTextField, 
      .row .vXMLLargeTextField, 
      div.autocomplete-wrapper-m2m {
        max-width: 450px;
      }
      
      .duplicate_p {
         border-style: solid;
         border: 1px solid #000000;
         border-radius: 10px;
         padding: 5px;
         background-color: #ffc6cb;
         display: none;
      }
   </style>
{% endblock %}

{% block javascripts %}
  {{ block.super }}
   <script type="text/javascript">
      function check_levels() {
        checks = $('input').filter(function() {
          return this.name.match(/check_.*/) 
        });
         
        add_it = true;
        last_level = false;
        {% for level in levels %}
          checks.each(function(index){
          /* For each checkbox in all checkboxes*/
             if ($(this).attr('check_required') == "True" && !($(this).attr('checked')) && $(this).attr('level') == "{{ level }}" ) {
                add_it = false;
             }
          });
          if ( add_it ) {
            $('#level_{{ level|cut:" " }}').addClass('level_complete');
            last_level = "{{ level }}";
          } else {
            $('#level_{{ level|cut:" " }}').removeClass('level_complete');
          }
        {% endfor %}
      }      
      $(document).ready(function() {
         check_levels();
      });
   </script>
   
   {% if add %}
   <script type="text/javascript">
      $(document).ready(function() {
         $('#id_fname').bind('change', function() {
            var first = $('#id_fname').val();
            var last = $('#id_lname').val();
            if (first && last) {
               $.post(  
                  "/admissions/ajax_check_duplicate_applicant/" + first + "/" + last + "/",
                  function(data){
                     if (data != "") {
                        $('#duplicate_p').show('fast');
                        $('#insert_point').html(data);
                     }
                  }  
               );
            }
         });
      });
   </script>    
   {% endif %}
   <script type="text/javascript">
      $(document).ready(function() {
         // Move Application boxes to the Process Status box
         $('div.application_decision').appendTo($('div.checklist'));
         $('div.application_decision_by').appendTo($('div.checklist'));
      });
   </script>
{% endblock %}


<!-- CONTENT SWORD override -->
{% block content %}
    <div class="grp-layout-container">
        <div class="grp-form-container">
            <form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post" id="{{ opts.module_name }}_form">{% csrf_token %}{% block form_top %}{% endblock %} 
                <div>
                    <!-- Popup Hidden Field -->
                    {% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %}
                    
                    <!-- No Submit-Row on Top -->

                    <!-- Errors -->
                    {% if errors %}
                        <p class="errornote">{% blocktrans count errors|length as counter %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %}</p>
                        <ul class="errorlist">{% for error in adminform.form.non_field_errors %}<li>{{ error }}</li>{% endfor %}</ul>
                    {% endif %}
          
          <!-- Fieldsets -->
          {% for fieldset in adminform %}
             {% if forloop.first %}
                <div style="float:left;">
                   {% include "admin/includes/fieldset.html" %}
                </div>
                <!--SWORD added check list-->
                <div style="float:left; margin-left: 10px;">
                   <fieldset class="grp-module module aligned">
                  <h2>Process Status - {{ current_level }}</h2> <input type="hidden" name="checkmark_data" value="1"/>
                  <div class="form-row checklist">
                      <div>
                        {% for level in levels %}
                           {% for check in level.checks %}
                            <input type="checkbox" level="{{ level }}" check_required="{{ check.required }}" name="check_{{ level|cut:" " }}_{{ check }}_{{ check.id }}" {% if check.checked %} checked="checked" {% endif %} onclick="check_levels()"/>
                            {{ check }}
                            {% if check.required %}
                              (R)
                            {% endif %}
                            <br/>
                           {% endfor %}
                           <span id="level_{{ level|cut:" " }}" class="level" name="level_{{ level|cut:" " }}"> {{ level }} </span> <br/>
                        {% endfor %}
                      </div>
                  </div>
                   </fieldset>
                </div>
             {% else %}
                <div style="clear:both;">
                {% include "admin/includes/fieldset.html" %}
                </div>
             {% endif %}
          {% endfor %}
          {% block after_field_sets %}{% endblock %}
                    
                    <!-- Inlines -->
                    {% for inline_admin_formset in inline_admin_formsets %}
                        {% include inline_admin_formset.opts.template %}
                    {% endfor %}
                    
                    {% block after_related_objects %}{% endblock %}
                    
                    <!-- Submit-Row -->
                    {% block submit_buttons_bottom %}{% submit_row %}{% endblock %}
                    
                    {% if adminform and add %}
                        {% block extrahead %}
                            {{ block.super }}
                            <script type="text/javascript">
                                (function($){
                                    $(function(){
                                        try {
                                            // focus on first form-field
                                            $("#{{ adminform.first_field.auto_id }}, #{{ adminform.first_field.auto_id }}_0")
                                            .eq(0).focus();
                                        } catch(e) {}
                                    });
                                }(django.jQuery));
                            </script>
                        {% endblock %}
                    {% endif %}
                    
                    <!-- JS for prepopulated fields -->
                    {% prepopulated_fields_js %}
                    
                </div>
            </form>
        </div>
    </div>
{% endblock %}
